package com.logis.ryanrqwork.ui.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.logis.ryanrqwork.DBController;
import com.logis.ryanrqwork.R;
import com.logis.ryanrqwork.dao.User;
import com.logis.ryanrqwork.daoutil.UserDaoController;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText edittext_username;
    private EditText edittext_password;
    private EditText edittext_password_again;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        edittext_username = ((EditText) findViewById(R.id.edittext_username));
        edittext_password = ((EditText) findViewById(R.id.edittext_password));
        edittext_password_again = ((EditText) findViewById(R.id.edittext_password_again));
        findViewById(R.id.button_enter).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(TextUtils.isEmpty(edittext_username.getText().toString())){
            Toast.makeText(this,"用户名不能为空",Toast.LENGTH_SHORT).show();
            return;
        }
        if(TextUtils.isEmpty(edittext_password.getText().toString()) ||TextUtils.isEmpty(edittext_password_again.getText().toString())){
            Toast.makeText(this,"密码不能为空",Toast.LENGTH_SHORT).show();
            return;
        }
        UserDaoController.registerUser(this,edittext_username.getText().toString(),edittext_password.getText().toString());
        Toast.makeText(this,"注册成功",Toast.LENGTH_SHORT).show();
        finish();
        //todo 判定用户是否重复
    }
}
